import {
  exportUrl,
  downloadTemplateUrl,
  getReturnWorkshopCodeList,
  getStatusList
} from '@/api/materialRequisition/mesRequisitionOrderMaterialsEditlog'

import { exportExcel } from '@/utils/judge'

// 列表头按钮配置
export const operateList = [
  {
    name: $i18n.t('common.export'),
    type: "primary",
    icon: "el-icon-download",
    handleName: "export", //点击时返回的标识
    url: exportUrl,
    //auth: "auth:operlog:export", //权限字段
  },
  // {
  //   name: $i18n.t("common.add"),
  //   type: "primary",
  //   icon: "el-icon-circle-plus-outline",
  //   handleName: "add", //点击时返回的标识
  // },
  // {
  //   name: $i18n.t("common.delete"),
  //   type: "danger",
  //   icon: "el-icon-delete",
  //   handleName: "deleteBatch", //点击时返回的标识
  //   isMultiple: true, // isSingle 表示必须选择一项//isMultiple: true, // 表示必须多选
  // },
  // {
  //   name: $i18n.t("common.import"),
  //   type: "primary",
  //   icon: "el-icon-circle-plus-outline",
  //   handleName: "import", //点击时返回的标识
  // },
]
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
]
// 搜索条件配置
export const searchConfig = {
  data () {
    const self = this
    return {
      searchConfig: {
        inline: true,
        formDesc: {
          orderNo: {
            type: 'input',
            label: $i18n.t('mesRequisitionOrderMaterialsEditlog.orderNo'),  // 单据编号
          },
          planCode: {
            type: 'input',
            label: $i18n.t('mesRequisitionOrderMaterialsEditlog.planCode'),  // 生产订单编码
          },
          // status: {
          //   type: 'select',
          //   label: $i18n.t('mesRequisitionOrderMaterialsEditlog.status'),  // 领料状态:0创建1领料中2已完成3已关闭
          //   prop: {
          //     value: "value",
          //     text: "description",
          //   },
          //   options: async (data) => {
          //     const list = await getStatusList()
          //     return list.data.result
          //   },
          // },
          materialName: {
            type: 'input',
            label: $i18n.t('mesRequisitionOrderMaterialsEditlog.materialName'),  // 物料名称
          },
          planTime: {
            type: 'datetimerange',
            label: $i18n.t('mesRequisitionOrderMaterialsEditlog.latestGetDate'),  // 最后配送时间
            attrs: {
              valueFormat: "yyyy-MM-dd HH:mm:ss",
              searchArrKey: ["planTimeMin", "planTimeMax"]
            },
          },
          returnWorkshopCode: {
            type: 'select',
            label: $i18n.t('mesRequisitionOrderMaterialsEditlog.returnWorkshopName'),  // 配送车间名称
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            options: async (data) => {
              const params = {
                modelingCode: self.$store.getters.factoryCode,
                level: 4,
                modelingType: "0",
              };
              const list = await getReturnWorkshopCodeList(params)
              return list.data.result
            },
          },
          returnWorkCellCode: {
            type: 'select',
            label: $i18n.t('mesRequisitionOrderMaterialsEditlog.returnWorkCellName'),  // 配送工位名称
            prop: {
              value: "modelingCode",
              text: "modelingName",
            },
            optionsLinkageFields: ["returnWorkshopCode"],
            options: async (data) => {
              if (!data.returnWorkshopCode) return [];
              let res = await getReturnWorkshopCodeList({
                modelingCode: data.returnWorkshopCode,
                level: 6,
              });
              return res.data.result;
            },
          },
        },
      }
    }
  }
}
// 新增/删除表单配置
export const formDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  formDesc: {
    requisitionOrderMaterialsId: {
      type: "number",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.requisitionOrderMaterialsId"),  // 外键 领料单明细表（mes_requisition_order_materials）
      layout: 12,
      required: true,
    },
    requisitionOrderId: {
      type: "number",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.requisitionOrderId"),  // 外键 领料单表（mes_requisition_order）
      layout: 12,
      required: true,
    },
    orderNo: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.orderNo"),  // 单据编号
      layout: 12,
      required: true,
    },
    orderLine: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.orderLine"),  // 单据行项目
      layout: 12,
      required: false,
    },
    orderType: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.orderType"),  // 单据类型
      layout: 12,
      required: false,
    },
    warehouseCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.warehouseCode"),  // 仓库编码
      layout: 12,
      required: false,
    },
    warehouseName: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.warehouseName"),  // 仓库名称
      layout: 12,
      required: false,
    },
    planCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.planCode"),  // 生产订单编码
      layout: 12,
      required: false,
    },
    prodCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.prodCode"),  // 产品编码
      layout: 12,
      required: true,
    },
    prodName: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.prodName"),  // 产品名称
      layout: 12,
      required: true,
    },
    materialCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.materialCode"),  // 物料编码
      layout: 12,
      required: false,
    },
    materialName: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.materialName"),  // 物料名称
      layout: 12,
      required: false,
    },
    unit: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.unit"),  // 计量单位名称
      layout: 12,
      required: true,
    },
    unitCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.unitCode"),  // 计量单位编码
      layout: 12,
      required: true,
    },
    planQty: {
      type: "number",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.planQty"),  // 计划数量
      layout: 12,
      required: true,
    },
    actualQty: {
      type: "number",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.actualQty"),  //  实际领料/退料数（已领/已退数--多次累加）
      layout: 12,
      required: true,
    },
    type: {
      type: "number",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.type"),  // 类型
      layout: 12,
      required: true,
    },
    status: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.status"),  // 领料状态
      layout: 12,
      required: true,
    },
    ifOverPick: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.ifOverPick"),  // 是否超领
      layout: 12,
      required: false,
    },
    overPickNum: {
      type: "number",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.overPickNum"),  // 超领数量
      layout: 12,
      required: false,
    },
    overPickReason: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.overPickReason"),  // 超领原因
      layout: 12,
      required: false,
    },
    overPickRemark: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.overPickRemark"),  // 超领备注
      layout: 12,
      required: false,
    },
    latestGetDate: {
      type: "datetime",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.latestGetDate"),  // 最后配送时间
      layout: 12,
      required: false,
      attrs: {
        "valueFormat": "yyyy-MM-dd HH:mm:ss",
      },
    },
    lastReturnDate: {
      type: "datetime",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.lastReturnDate"),  // 无用时间
      layout: 12,
      required: false,
      attrs: {
        "valueFormat": "yyyy-MM-dd HH:mm:ss",
      },
    },
    returnWorkshopCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.returnWorkshopCode"),  // 配送车间编码
      layout: 12,
      required: false,
    },
    returnWorkshopName: {
      type: "select",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.returnWorkshopName"),  // 配送车间名称
      layout: 12,
      required: false,
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getReturnWorkshopNameList()
        return list.data.result
      },
    },
    returnWorkCellCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.returnWorkCellCode"),  // 配送工位编码
      layout: 12,
      required: false,
    },
    returnWorkCellName: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.returnWorkCellName"),  // 配送工位名称
      layout: 12,
      required: false,
    },
    actionType: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.actionType"),  // 操作类型（0-BOM初始化，1、手工添加，2、其他系统拉取）
      layout: 12,
      required: false,
    },
    sourceType: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.sourceType"),  // 数据来源 1-mes 2-wms 3-其它
      layout: 12,
      required: true,
    },
    snControl: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.snControl"),  // SN控制--物料控制，Y(管理SN)/N(管理数量)
      layout: 12,
      required: true,
    },
    version: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.version"),  // 版本
      layout: 12,
      required: false,
    },
    batchNo: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.batchNo"),  // 批次号
      layout: 12,
      required: false,
    },
    factoryCode: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.factoryCode"),  // 工厂编码
      layout: 12,
      required: true,
    },
    operationBy: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.operationBy"),  // 操作人
      layout: 12,
      required: true,
    },
    operationByName: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.operationByName"),  // 操作人名称
      layout: 12,
      required: true,
    },
    operationTime: {
      type: "datetime",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.operationTime"),  // 操作时间
      layout: 12,
      required: true,
      attrs: {
        "valueFormat": "yyyy-MM-dd HH:mm:ss",
      },
    },
    operationType: {
      type: "input",
      label: $i18n.t("mesRequisitionOrderMaterialsEditlog.operationType"),  // 操作类型 1-修改，2-关闭
      layout: 12,
      required: false,
    },
  },
}
//导入数据
export const importFormDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  formDesc: {
    model: {
      type: "button",
      label: "",
      layout: 24,
      required: false,
      title: $i18n.t("common.downloadTemplate"), // 下载模板
      style: {
        color: '#1867c0',
        fontSize: '14px'
      },
      on: {
        click: () => {
          exportExcel(downloadTemplateUrl)
        }
      }
    },
    file: {
      type: "input",
      label: $i18n.t("common.chooseFile"),
      layout: 24,
      // required: true,

    },
  }
}

